<?php	
	include('db_connection.php');
	class scheduled_meeting{
            
            function add_trainer_scheduled($tranier_id = '',$course_id = ''){
                
                $chk_query = mysql_query("select * from tbl_tranier_free_time where t_trainer_id = ".$tranier_id."
and t_time_solt_id = ".$_POST['time_slot']." and t_date = '".$_POST['date']."' ");
                $result_query = mysql_fetch_assoc($chk_query);
                
                $free_time_id = $result_query['t_id'];
               
                 
                
                $update_query = " UPDATE `tbl_tranier_free_time` 
                    SET `t_course_id`=".$_POST['student_course'].",`t_student_id`=".$_POST['user_detail_id'].",`t_status`=2
                        WHERE t_id = '".$free_time_id."'";
                         mysql_query( $update_query);
                
                $tranier_query = mysql_query("select * from tbl_admin 
                    where is_trainer = 1 and id = '".$tranier_id."' ");
                   $traniee_data = mysql_fetch_assoc($tranier_query);
                   
                $student_detail = $this->student_scheduled_array($_SESSION['id']," and a.id = ".$_POST['user_detail_id']);
                $msg = "Record saved successfully";
                   
                /* This funcion is used for  sent mail. ends here */
                
                        $student_name = $student_detail[0]['student_username'];
                        $student_email = $student_detail[0]['student_email'];
                        $course_name = $student_detail[0]['course_name'];
                        $Date = $student_detail[0]['t_date'];
                        $Time = $student_detail[0]['course_slot'];
                        $tranier_name = $student_detail[0]['name'];
                
                        ob_start();
                        include_once('../../mailtemplate/scheduled_meeting_by_student.php');
                        $mail_body = ob_get_contents();
                        ob_end_clean();
                       
                     $mail_to = $student_detail[0]['email'];
                     $mail_subject="Student Detail";
                     $headers  = 'MIME-Version: 1.0' . "\r\n";
                     $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
                     $headers .= 'From:RV Training<info@rvtraining.net>' . "\r\n";
                     mail($mail_to,$mail_subject,$mail_body, $headers);
                       # echo $mail_body;exit;
                     return $msg;
                
            }
            
            function student_array(){
                $student_query = mysql_query("select * from tbl_user where is_paid = 1 and is_active = 1 order by username");
                $finalArray = array();
                while($student_data = mysql_fetch_array($student_query))
                {
                    $finalArray[$student_data['id']]['name'] = ucfirst($student_data['username']);
                    $finalArray[$student_data['id']]['email'] = $student_data['email'];
                }
                 return $finalArray;
            }
            
            function course_array($student_id = ""){
                if($student_id != ''){
                    $where = "where a.user_id = '".$student_id."'";
                }else{
                    $where = "";
                }
                $course_query = mysql_query("select *,b.id as course_id from tbl_user_details a
                    Join tbl_courses b ON a.course_id = b.id ".$where."
                     order by course_name");
                $finalArray = array();
                while($course_data = mysql_fetch_array($course_query))
                {
                    $finalArray[$course_data['course_id']] = ucfirst($course_data['course_name']);
                }
                 return $finalArray;
            }
            
            function traniee_array($course_id = ''){
                if($course_id != ''){
                    $where = "and a.course = '".$course_id."'";
                }else{
                    $where = "";
                }
                
                $course_query = mysql_query("select *,b.id as course_id,a.id as admin_id from tbl_admin a
                    Join tbl_courses b ON a.course = b.id 
                    where is_trainer = 1 ".$where."  order by course_name ");
                $finalArray = array();
                while($course_data = mysql_fetch_array($course_query))
                {
                    $finalArray[$course_data['admin_id']] = ucfirst($course_data['Name']);
                }
                 return $finalArray;
            }
            
            function student_Delete_scheduled($t_id){
                $update_query = " UPDATE `tbl_tranier_free_time` 
                    SET `t_course_id`=0,`t_student_id`=0,`t_status`=1
                        WHERE t_id = '".$t_id."'";
                    mysql_query( $update_query);
                    $msg =  "Record Delete Successfully";
                    return $msg;
            }
            
            function student_scheduled_array($user_id,$where = "",$offset = "" ,$limit = ""){
                $page_cond = '';
                if($limit != ''){
                  $page_cond = "LIMIT " . $offset . ", " . $limit;
                }
               
              
               
                
                $query = mysql_query("SELECT c.`course_name`,k.course_slot,e.name,e.email,e.id as trainerid,
                    a.id AS user_detail_id,u.username as student_username,u.email as student_email,a.course_id AS user_course_id ,d.*,f.* 
FROM tbl_user_details a
JOIN tbl_user u ON a.`user_id` = u.id 
JOIN tbl_courses c ON a.`course_id` = c.`id` 
LEFT JOIN  tbl_trainee_schedule d ON d.student_id = a.id
LEFT JOIN tbl_tranier_free_time f ON a.id = f.`t_student_id` 
LEFT JOIN tbl_timeslot k ON k.id = f.`t_time_solt_id`
LEFT JOIN tbl_admin e ON d.`trainer_id` = e.id
WHERE (a.via_paid = 1 OR a.via_paid = 2 OR a.via_paid = 3 ) and a.is_ebook = 0
AND u.id = '".$user_id."' ".$where."  ".$page_cond."")or die(mysql_error());
                
                $finalArray = array();
                if(mysql_num_rows($query) > 0 ){
                    while ($row = mysql_fetch_array($query)){
                        $finalArray[] = $row;
                    }
                }
                return $finalArray;
            }
	}
?>